<!-- 实训任务 -->
<template>
  <div>
    <el-tabs type="border-card" class="demo-tabs" v-model="curtab">
      <el-tab-pane name="first">
        <template #label>
          <span class="custom-tabs-label">
            <!-- <el-icon><calendar /></el-icon> -->
            <span class="circle" :class="{ currentcircle: curtab == 'first' }"></span>
            <span>全部</span>
          </span>
        </template>

        <!-- 状态描述 -->
        <div class="describe behindbox">
          <i>&#xe72d;</i>
          <span style="margin-right: 50px">已完成</span>
          <i>&#xe636;</i>
          <span>未完成</span>
          <span style="margin-left: 730px">状态</span>
        </div>

        <!-- 实训列表 -->
        <ul class="ulbox">
          <li data-eid="11" @click="openTrainSum(item.lesson_id, item.id)" v-for="(item, index) in practicelist"
            :key="index">
            <div class="iconcontainer behindbox">
              <i v-show="false">&#xe72d;</i>
              <i v-show="true">&#xe636;</i>
            </div>
            <p>{{ item.lesson_name }}</p>
            <!-- <p class="publishtime">发布时间：2024-09-29 14:14:00</p> -->
            <span class="statuslabel">{{ practicestatus[item.status] }}</span>
          </li>
        </ul>
      </el-tab-pane>
      <el-tab-pane name="second">
        <template #label>
          <span class="custom-tabs-label">
            <span class="circle" :class="{ currentcircle: curtab == 'second' }"></span>
            <span>已完成</span>
          </span>
        </template>

        <!-- 状态描述 -->
        <div class="describe behindbox">
          <i>&#xe72d;</i>
          <span style="margin-right: 50px">已完成</span>
          <i>&#xe636;</i>
          <span>未完成</span>
          <span style="margin-left: 730px">状态</span>
        </div>

        <!-- 实训列表 -->
        <ul class="ulbox">
          <li data-eid="11" @click="openTrainSum(item.lesson_id, item.id)" v-for="(item, index) in donepracticelist"
            :key="index">
            <div class="iconcontainer behindbox">
              <i v-show="false">&#xe72d;</i>
              <i v-show="true">&#xe636;</i>
            </div>
            <p>{{ item.lesson_name }}</p>
            <!-- <p class="publishtime">发布时间：2024-09-29 14:14:00</p> -->
            <span class="statuslabel">{{ practicestatus[item.status] }}</span>
          </li>
        </ul>
      </el-tab-pane>
      <el-tab-pane name="third">
        <template #label>
          <span class="custom-tabs-label">
            <!-- <el-icon><calendar /></el-icon> -->
            <span class="circle" :class="{ currentcircle: curtab == 'third' }"></span>
            <span>未完成</span>
          </span>
        </template>

        <!-- 状态描述 -->
        <div class="describe behindbox">
          <i>&#xe72d;</i>
          <span style="margin-right: 50px">已完成</span>
          <i>&#xe636;</i>
          <span>未完成</span>
          <span style="margin-left: 730px">状态</span>
        </div>

        <!-- 实训列表 -->
        <ul class="ulbox">
          <li data-eid="11" @click="openTrainSum(item.lesson_id, item.id)" v-for="(item, index) in nodonepracticelist"
            :key="index">
            <div class="iconcontainer behindbox">
              <i v-show="false">&#xe72d;</i>
              <i v-show="true">&#xe636;</i>
            </div>
            <p>{{ item.lesson_name }}</p>
            <!-- <p class="publishtime">发布时间：2024-09-29 14:14:00</p> -->
            <span class="statuslabel">{{ practicestatus[item.status] }}</span>
          </li>
        </ul>
      </el-tab-pane>
    </el-tabs>

    <el-dialog v-model="dialogExamVisible" :width="600">
      <div class="studentinfo">
        <div class="status">
          <p>{{ practicedetail.detaildone ? '已完成' : '未完成' }}</p>
        </div>
        <div class="examinfo">
          <!-- <p>电动机单向连续运转接线(带电动控制)</p> -->
          <p>{{ practicedetail.lesson_name }}</p>
          <div class="score" v-if="practicedetail.detaildone">
            <span>技能分&nbsp;<em>{{ practicedetail.score1 }}</em>&nbsp;分</span>
            <span>素养分&nbsp;<em>{{ practicedetail.score2 }}</em>&nbsp;分</span>
          </div>
          <div v-else class="noscore">未查询到相关得分</div>
        </div>
        <div class="name_class">
          <ul>
            <li>
              <div class="labelbox">姓名：</div>
              <div class="contentbox">{{ username }}</div>
            </li>
            <li>
              <div class="labelbox">小组：</div>
              <div class="contentbox">{{ practicedetail.title }}</div>
            </li>
            <!-- <li>
              <div class="labelbox">组内成员：</div>
              <div class="contentbox">张三、李四、王五、赵六</div>
            </li> -->
            <!-- <li>
              <div class="labelbox">工位：</div>
              <div class="contentbox">设备3</div>
            </li> -->
            <li>
              <div class="labelbox">设备账号：</div>
              <div class="contentbox">{{ practicedetail.sn }}</div>
            </li>
            <li>
              <div class="labelbox">设备密码：</div>
              <div class="contentbox">{{ practicedetail.group_pass }}</div>
            </li>
          </ul>
        </div>
        <div class="btnbox">
          <el-button type="primary" class="btnstyle"
            @click="gotoTrainDetail(practicedetail.lesson_id)">查询实训详情</el-button>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script setup>
import { ref, onMounted, inject, defineProps } from 'vue'

// 加载user模块 以及底下变量
import { storeToRefs } from 'pinia'
import useStore from '@/store'
const { user } = useStore()
let { username, avatar, uid } = storeToRefs(user)

// 导入请求路径
import api from '@/request/api'
// 注入网络请求方法
const axios = inject('axios')

import { useRouter } from 'vue-router'
// 初始化路由实例
const router = useRouter()

// 定义props
const props = defineProps({
  lessonid: {
    default: 0,
    required: true,
    type: Number
  }
})

// 模态框显示标识
const dialogExamVisible = ref(false)
let curtab = ref('first')

// 实训状态
let practicestatus = ref(['未开始', '进行中', '已结束'])
// 实训小组列表
let practicelist = ref([])
let donepracticelist = ref([])
let nodonepracticelist = ref([])

// 实训小组详情
let practicedetail = ref({})

onMounted(async () => {
  console.log('props.lessonid', props.lessonid)

  // 获取实训小组列表
  await getPracticeGroup()
})

// 获取实训小组列表
async function getPracticeGroup() {
  let res = await axios.post(api.practicemygrouplist, {
    uid: uid.value
  })

  if (res.code == 0 && res.data.length != 0) {
    practicelist.value = res.data
  } else {
    showMessage('warning', res.msg)
  }
  // console.log('practicemylist', res)
}
// 打开实训概述
async function openTrainSum(lesson_id, id) {

  let detail = await axios.post(api.practicegroupdetail, {
    id: id
  })
  // 查询失败
  if (detail.code !== 0) return showMessage('error', detail.msg)

  // 实训得分接口 获取做得分数据补充
  let practicescore = await axios.post(api.mypracticescore, {
    uid: uid.value,
    id: lesson_id
  })
  if (practicescore.code == 0) {
    // 如果没有记录，证明实训未完成；此处表示实训已完成
    detail.data.detaildone = true
    detail.data.score1 = practicescore.data.score1
    detail.data.score2 = practicescore.data.score2
    detail.data.score3 = practicescore.data.score3
  }

  practicedetail.value = detail.data
  dialogExamVisible.value = true
}

// 跳转实训详情
function gotoTrainDetail(lesson_id) {

  dialogExamVisible.value = false

  router.replace({
    name: 'Taskdetail',
    state: {
      lesson_id
    }
  })

  // 新页面打开
  // const hrefstr = router.resolve({
  //   name: 'Examdetail',
  //   state: {
  //     eid
  //   }
  // }).href
  // window.open(hrefstr, '_blank')
}

// 信息提示
const showMessage = (msgtype, msgstr) => {
  ElMessage({
    showClose: true,
    message: msgstr,
    type: msgtype,
    offset: 50
  })
}
</script>

<style scoped>
.demo-tabs>.el-tabs__content {
  padding: 32px;
  color: #6b778c;
  font-size: 32px;
  font-weight: 600;
}

.demo-tabs .custom-tabs-label .el-icon {
  vertical-align: middle;
}

.demo-tabs .custom-tabs-label span {
  vertical-align: middle;
  margin-left: 4px;
}

.circle {
  box-sizing: border-box;
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-right: 4px;
  /* background-color: skyblue; */
  border: 1px solid skyblue;
}

.describe {
  display: flex;
  align-items: center;
  height: 30px;
  margin-bottom: 20px;
}

.describe span {
  font-weight: 700 !important;
}

.currentcircle {
  background-color: skyblue;
  border: 0;
}

.behindbox i {
  display: block;
  font-family: 'iconfont2' !important;
  font-size: 16px;
  color: #afc5cc;
  margin-right: 10px;
}

.ulbox li {
  display: flex;
  align-items: center;
  height: 40px;
  /* background-color: pink; */
  border-bottom: 1px solid #eee;
  cursor: pointer;
}

.ulbox li p {
  width: 750px;
  margin-right: 150px;
}

.statuslabel {
  font-size: 14px;
}

.studentinfo {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 90%;
  /* height: 150px; */
  margin: 0 auto;
  /* background-color: pink; */
  padding-top: 20px;
}

.studentinfo ul li {
  display: flex;
  height: 28px;
  margin: 0px auto;
  align-items: center;
}

.examinfo {
  width: 70%;
  height: 100px;
  margin: 0 auto;
  /* background-color: skyblue; */
  padding-top: 20px;
}

.examinfo p {
  text-align: center;
  font-size: 14px;
  font-weight: 600;
}

.examinfo .score {
  width: 60%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 10px auto 0;
}

.noscore {
  width: 60%;
  margin: 10px auto 0;
  text-align: center;
  font-size: 14px;
}

.examinfo .score em {
  font-size: 20px;
}

.name_class {
  box-sizing: border-box;
  width: 280px;
  padding: 10px 20px;
  font-size: 14px !important;
  background-color: #f2f2f2;
}

.name_class .contentbox {
  font-weight: 550;
}

.btnbox {
  text-align: center;
  margin-top: 40px;
  margin-bottom: 90px;
}

.btnstyle {
  width: 200px;
  margin: 0 auto;
}

.studentinfo .status {
  width: 240px;
  height: 100%;
  text-align: center;
}

.studentinfo .status p {
  color: #0099fe;
  font-size: 30px;
  font-weight: 700;
}
</style>

<style scoped>
.ulbox li .publishtime {
  width: 260px;
  font-size: 14px;
  margin-right: 0px;
}
</style>
